package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.ProjectInfoDto;
import com.crm.jdy.common.dto.WListInfoDto;
import com.crm.jdy.common.pojo.ProjectInfo;
import com.crm.jdy.common.pojo.WListInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.WListInfoService;
import com.crm.jdy.service.project.ProjectInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 仓库清点列表信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "wListInfo", description ="仓库清点列表信息")
@RestController
@RequestMapping("/wListInfo")
public class WListInfoController{


    @Reference(version = "${service.version}", check = false)
    WListInfoService wListInfoService;

    @RateLimit()
    @ApiOperation("仓库清点列表信息")
    @PostMapping("/seleteWListInfo")
    public ResultVo seleteWListInfo(@RequestBody WListInfoDto projectInfoDto){
        PageInfo<WListInfo> list = wListInfoService.seleteWListInfo(projectInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新仓库清点列表信息")
    @PostMapping("/updateWListInfo")
    public ResultVo updateWListInfo(@ApiParam(value = "projectInfo", required = true)
                                      @Validated @RequestBody WListInfo projectInfo){
        boolean index = wListInfoService.updateWListInfo(projectInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加仓库清点列表信息")
    @PostMapping("/addWListInfo")
    public ResultVo addWListInfo(@ApiParam(name = "projectInfo", required = false)
                                   @Validated @RequestBody WListInfo projectInfo){
        boolean list  = wListInfoService.addWListInfo(projectInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除仓库清点列表信息")
    @DeleteMapping("deleteWListInfo/{listId}")
    public ResultVo deleteWListInfo(@NotNull @ApiParam(name = "listId", value = "listId", required = true) @PathVariable String listId){
        boolean b = wListInfoService.removeWListInfo(listId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}